Skip to content

config: strip credentials on cross-host redirects#901

Open
roidelapluie wants to merge 1 commit into
prometheus:mainfrom
roidelapluie:roidelapluie/fixredirectauth
Open

config: strip credentials on cross-host redirects#901
roidelapluie wants to merge 1 commit into
prometheus:mainfrom
roidelapluie:roidelapluie/fixredirectauth

Conversation

@roidelapluie
Copy link
Copy Markdown
Member

When FollowRedirects is true, credentials (Authorization header, Cookie headers set via HTTPHeaders) were forwarded to any redirect target, including cross-host redirects.

Fix by marking cross-host redirects in the request context inside CheckRedirect, then having each credential round-tripper (bearer, basic auth, OAuth2) skip adding credentials for marked requests. A new sensitiveHeadersStripRT also strips sensitive headers added by headersRoundTripper on cross-host redirects.

This aligns to Go's HTTP client behaviour.

@roidelapluie roidelapluie force-pushed the roidelapluie/fixredirectauth branch from 9a3494d to c9d52ff Compare April 21, 2026 08:52
@roidelapluie roidelapluie force-pushed the roidelapluie/fixredirectauth branch from c9d52ff to 5c585f7 Compare May 19, 2026 14:46
When FollowRedirects is true, credentials (Authorization header, Cookie
headers set via HTTPHeaders) were forwarded to any redirect target,
including cross-host redirects.

Fix by detecting cross-host redirects via isCrossHostRedirect, which
walks the req.Response chain to find the original request's hostname and
compares it to the current destination. Each credential round-tripper
(bearer, basic auth, OAuth2) skips adding credentials when
isCrossHostRedirect returns true. A new sensitiveHeadersStripRT also
strips sensitive headers added by headersRoundTripper on cross-host
redirects.

This approach requires no CheckRedirect hook and works whether the
caller uses NewClientFromConfig or a custom http.Client built from
NewRoundTripperFromConfigWithContext directly.

This aligns to Go's HTTP client behaviour.

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
@roidelapluie roidelapluie force-pushed the roidelapluie/fixredirectauth branch from 5c585f7 to 19e8002 Compare May 20, 2026 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant